<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2022-11-09 17:29:20
 * @Last Modified time: 2023-02-22 16:04:01
 */
namespace frank\exception;
use think\exception\Handle;
use think\exception\HttpException;
use think\exception\HttpResponseException;
use think\facade\View;
use think\facade\Request;
use think\Response;
use Throwable;

/**
 * Class ApiException
 * 自定义异常类的基类
 */
class ApiException extends Handle
{
    public function render($request, Throwable $e): Response
    { 
        if(method_exists($e, 'getResponse')){
            return parent::render($request, $e);
        }
        $result = [
            'code' => $e->getCode(),
            'message' => lang($e->getMessage()),
            'time' => $request->server('REQUEST_TIME'),
            'data' => '',
        ]; 
        if(env('app_debug') === true){
            return parent::render($request, $e);
        }
        return json($result);exit;
    }
}